package com.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class test1 {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        String url="jdbc:mysql://127.0.0.1:3306/myschool?usrUnicode=true&charset=utf8&serverTimezone=Asia/Shanghai";
        String username="root";
        String password="root";
        try {
            Connection conn = DriverManager.getConnection(url, username, password);
            //System.out.println(conn);
            String sql="insert into students (`loginpwd`,`studentname`,`sex`) " +
                    " values (?,?,?)";
            PreparedStatement preparedStatement = conn.prepareStatement(sql);
            preparedStatement.setString(1,"123456789");
            preparedStatement.setString(2,"西八");
            preparedStatement.setString(3,"男");

            int i = preparedStatement.executeUpdate();
            System.out.println(i>0 ? "执行成功":"执行失败");

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }
}
